<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>消息推送(Message-Push-withDwr)</title>

<!-- 引入的dwr的js和你使用dwr create的js-->

<script src="${pageContext.request.contextPath}/resources/jslib/jquery-1.10.2.min.js"></script>
<script src="${pageContext.request.contextPath}/dwr/engine.js"></script>
<script src="${pageContext.request.contextPath}/dwr/util.js"></script>
<script src="${pageContext.request.contextPath}/dwr/interface/MessagePush.js"></script>

</head>
<body>

		Person : <div id="reverseAjaxPerson"></div>
		News	 : <div id="reverseAjaxNews"></div>
		
		
<script type="text/javascript">

		$(document).ready(function () {
		  	  	dwr.engine.setActiveReverseAjax(true);
		    	dwr.engine.setNotifyServerOnPageUnload(true);
		    	//这里可以添加用户id传给后台作为当前页面的sessionScript标识
		});

		//页面加载时调用
/* 		function onPageLoad(){
			dwr.engine.setActiveReverseAjax(true);
			dwr.engine.setNotifyServerOnPageUnload(true);
		  /*   var userId = '001';
		    MessagePush.onPageLoad(userId); 
		 } */
		 
		//反向Ajax回调函数
		function setData(data) {
			var list = data.obj;
			if(data.type == "person"){
				for(var i in list){
					var age = list[i].age;
					var name = list[i].name;
					document.getElementById("reverseAjaxPerson").innerHTML += "<h2>name=" + age + ", 	age="+name+"</h2>";
				}
			}else if(data.type == "news"){
				for(var i in list){
					var content = list[i].content;
					var title = list[i].title;
					document.getElementById("reverseAjaxNews").innerHTML += "<h2>name=" + title + ", 	age="+content+"</h2>";
				}
			}
		}
		 
		 //错误提示消除
	    dwr.engine._errorHandler = function (message, ex) {
	        dwr.engine._debug("出错信息: " + ex.name + ", " + ex.message, true);
	    };
</script>
</body>
</html>